package com.iamteer.day15;

import java.util.LinkedList;

/**
用 LinkedList 实现堆栈和队列
 */

//用 LinkedList 模拟堆栈
class StackList {

	LinkedList linkedList;
	
	public StackList() {
		linkedList = new LinkedList();
	}
	
	//进栈
	public void push(Object o){
		linkedList.push(o);
	}
	
	//出栈
	public  Object pop(){
		return linkedList.pop();
	}
	
	//获取
	public int size(){
		return linkedList.size();
	}
}

//用 LinkedList 模拟队列
class QueueList{
	LinkedList linkedList;
	
	public QueueList() {
		linkedList = new LinkedList();
	}
	
	public void EnQueue(Object object){
		linkedList.offer(object);
	}
	
	public Object DeQueue(){
		return linkedList.poll();
	}
	
	public int size(){
		return linkedList.size();
	}
}

public class StackQueue {
	
	public static void main(String[] args) {
		StackList stackList = new StackList();
		
		stackList.push("张三");
		stackList.push("李四");
		stackList.push("王五");
		
		int length = stackList.size();
		for (int i = 0; i < length; i++) {
			System.out.println(stackList.pop());
		}
		System.out.println("---------------------------------");
		
		QueueList queueList = new QueueList();
		
		queueList.EnQueue("张三");
		queueList.EnQueue("李四");
		queueList.EnQueue("王五");
		queueList.EnQueue("赵六");
		
		length = queueList.size();
		for (int i = 0; i < length; i++) {
			System.out.println(queueList.DeQueue());
		}
	}

}
